//! 提供了开发工具宏
//!
//! 用于快速创建 [crate::preclude::Loader] 类型
//!
//!

use crate::preclude::{Package, Provide};

#[allow(unused)]
pub trait IntoPackage {
    fn into_package(self) -> Package;
}

impl IntoPackage for Package {
    fn into_package(self) -> Package {
        self
    }
}

impl<T: Provide> IntoPackage for T {
    fn into_package(self) -> Package {
        self.provide_package()
    }
}

/// 创建 `Loader` 的声明宏
///
/// 用于快速创建 [crate::preclude::Loader] 类型
#[macro_export]
macro_rules! loader_from {
    () => {{
        $crate::loader::Loader::new()
    }};

    (@package $val:expr) => {{
        $crate::utils::macros::loader_from::IntoPackage::into_package($val)
    }};

    ($val:expr) => {{
        let mut loader = loader_from!();
        loader.add_package(loader_from!(@package $val));
        loader
    }};


    ($($val:expr),+ $(,)?) => {{
        let mut loader = loader_from!();
        $(loader.add_package(loader_from!(@package $val));)+
        loader
    }};
}

#[cfg(test)]
mod test {

    #[test]
    fn test_loader_from() {}
}
